package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.MallProductUseintegralruleLink;
import com.ktgj.customer.service.IMallProductUseintegralruleLinkService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 商城商品使用积分规则Controller
 * 
 * @author ruoyi
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/link")
public class MallProductUseintegralruleLinkController extends BaseController
{
    @Autowired
    private IMallProductUseintegralruleLinkService mallProductUseintegralruleLinkService;

    /**
     * 查询商城商品使用积分规则列表
     */
    @PreAuthorize(hasPermi = "customer:link:list")
    @GetMapping("/list")
    public TableDataInfo list(MallProductUseintegralruleLink mallProductUseintegralruleLink)
    {
        startPage();
        List<MallProductUseintegralruleLink> list = mallProductUseintegralruleLinkService.selectMallProductUseintegralruleLinkList(mallProductUseintegralruleLink);
        return getDataTable(list);
    }

    /**
     * 导出商城商品使用积分规则列表
     */
    @PreAuthorize(hasPermi = "customer:link:export")
    @Log(title = "商城商品使用积分规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductUseintegralruleLink mallProductUseintegralruleLink) throws IOException
    {
        List<MallProductUseintegralruleLink> list = mallProductUseintegralruleLinkService.selectMallProductUseintegralruleLinkList(mallProductUseintegralruleLink);
        ExcelUtil<MallProductUseintegralruleLink> util = new ExcelUtil<MallProductUseintegralruleLink>(MallProductUseintegralruleLink.class);
        util.exportExcel(response, list, "商城商品使用积分规则数据");
    }

    /**
     * 获取商城商品使用积分规则详细信息
     */
    @PreAuthorize(hasPermi = "customer:link:query")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return AjaxResult.success(mallProductUseintegralruleLinkService.selectMallProductUseintegralruleLinkById(linkId));
    }

    /**
     * 新增商城商品使用积分规则
     */
    //@PreAuthorize(hasPermi = "customer:link:add")
    @Log(title = "商城商品使用积分规则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MallProductUseintegralruleLink mallProductUseintegralruleLink)
    {
        return toAjax(mallProductUseintegralruleLinkService.insertMallProductUseintegralruleLink(mallProductUseintegralruleLink));
    }

    /**
     * 修改商城商品使用积分规则
     */
    //@PreAuthorize(hasPermi = "customer:link:edit")
    @Log(title = "商城商品使用积分规则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody MallProductUseintegralruleLink mallProductUseintegralruleLink)
    {
        return toAjax(mallProductUseintegralruleLinkService.updateMallProductUseintegralruleLink(mallProductUseintegralruleLink));
    }

    /**
     * 删除商城商品使用积分规则
     */
    @PreAuthorize(hasPermi = "customer:link:remove")
    @Log(title = "商城商品使用积分规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(mallProductUseintegralruleLinkService.deleteMallProductUseintegralruleLinkByIds(linkIds));
    }

    /**
     * 查询商品积分规则
     * @param map
     * @return
     */
    @PostMapping("/queryUseintegralruleLinkByProductId")
    public AjaxResult queryUseintegralruleLinkByProductId(@RequestBody Map<?, ?> map) {
        if (map.get("productId") != null && !map.get("productId").toString().equals("") && map.get("productSpecId") != null && !map.get("productSpecId").toString().equals("")) {
            Long productId = Long.valueOf(map.get("productId").toString());
            Long productSpecId = Long.valueOf(map.get("productSpecId").toString());
            MallProductUseintegralruleLink useintegralruleLinks = mallProductUseintegralruleLinkService.queryUseintegralruleLinkByProductId(productId, productSpecId);
            return AjaxResult.success(useintegralruleLinks);
        } else {
            return AjaxResult.error("缺少必要参数！");
        }
    }

    /**
     * 删除商城商品使用积分规则信息
     * @param map
     * @return
     */
    @PostMapping("/deleteById")
    public AjaxResult deleteMallProductUseintegralruleLinkById(@RequestBody Map<?, ?> map) {
        if (map.get("linkId") != null && !map.get("linkId").toString().equals("")) {
            Long linkId = Long.valueOf(map.get("linkId").toString());
            return toAjax(mallProductUseintegralruleLinkService.deleteMallProductUseintegralruleLinkById(linkId));
        } else {
            return AjaxResult.error("缺少必要参数！");
        }
    }
}
